package com.maximporges.riatest;

import java.util.Properties;

public class Configuration
{
   public static final String INTEGRATION_CLASS_NAME_KEY = "integrationClassName";
   
   private String integrationClassName;
   private Properties configuration;

   public Configuration assemble(Properties configProperties)
   {
      setConfiguration(configProperties);
      
      String integrationRunnerClassName = getConfiguration().getProperty(INTEGRATION_CLASS_NAME_KEY);
      if (integrationRunnerClassName == null)
      {
         throw new RuntimeException("The property " + INTEGRATION_CLASS_NAME_KEY + " was not found in the configuration file.");
      }
      
      setIntegrationClassName(integrationRunnerClassName);

      //TODO: Holding on to this so we can have a command-line configuration as well as properties files
//      configurationParameters = new HashMap<String, String>();
//      for (int i = 1; i < args.length; i++)
//      {
//         String argument = args[i];
//         int indexOfEqualsCharacter = argument.indexOf('=');
//         if ((indexOfEqualsCharacter == -1) || (indexOfEqualsCharacter == 0))
//         {
//            throw new RuntimeException(argument + " is not a valid key/value pair of the form key=value.");
//         }
//         
//         String key = argument.substring(0, indexOfEqualsCharacter);
//         String value = argument.substring(indexOfEqualsCharacter + 1, argument.length());
//         configurationParameters.put(key, value);
//      }
      
      return this;
   }

   public String getIntegrationClassName()
   {
      return integrationClassName;
   }

   public void setIntegrationClassName(String integrationClassName)
   {
      this.integrationClassName = integrationClassName;
   }

   public Properties getConfiguration()
   {
      return configuration;
   }

   public void setConfiguration(Properties configuration)
   {
      this.configuration = configuration;
   }
}
